package tp_lab1_liczba;

import junit.framework.AssertionFailedError;
import junit.framework.TestCase;

public class LiczbaTest extends TestCase {
	private Liczba liczba;

	public void setUp() {
		liczba = new Liczba();
	}

	public void testAssertStringEquals() {
		liczba.setDec(17);
		try {
			assertEquals(liczba.convertFromDec(3), "122");
		} catch (WrongNumberException e) {
			fail("WrongNumberException should not occure, but it did");
		}
	}

	public void testShouldThrowFailWhenHexIsNotWorking() {
		liczba.setDec(10);
		boolean isSameAsA = false;
		try {
			if (liczba.convertFromDec(16).equals("A"))
				isSameAsA = true;
		} catch (WrongNumberException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		assertEquals(null, true, isSameAsA);
	}

	public void testShouldThrowExceptionWhenDecIsNegative() {
		liczba.setDec(-17);
		boolean wasException = false;
		try {
			liczba.convertFromDec(3);
		} catch (WrongNumberException e) {
			wasException = true;
		}
		assertTrue(null, wasException == true);
	}

	public void testShouldThrowExceptionWhenBaseIsLowerThanBinary() {
		liczba.setDec(12);
		boolean wasException = false;
		try {
			liczba.convertFromDec(1);
		} catch (WrongNumberException e) {
			wasException = true;
		}
		assertFalse(null, wasException == false);
	}

	public void testShouldThrowExceptionWhenBaseIsHigherThanHex() {
		liczba.setDec(12);
		boolean wasException = false;
		try {
			liczba.convertFromDec(17);
		} catch (WrongNumberException e) {
			wasException = true;
		}
		assertTrue(wasException == true);
	}

	public void testfail() {
		throw new AssertionFailedError("Sth goes wrong.");
	}
}
